#include <iostream>
#include <thread>

void do_something(int i)
{
    std::cout << i << "do something" << std::endl;
}

struct func
{
    int &m_i;

    func(int &i) : m_i(i) {}

    void operator()()
    {
        for (unsigned int j = 0; j < m_i; j++)
        {
            do_something(j);
        }
    }
};

void do_something_in_current_thread()
{
    std::cout << "thread: " << std::this_thread::get_id() << std::endl;
}

void oops()
{
    int some_local_state = 0;
    func my_func(some_local_state);
    std::thread my_thread(my_func);
    // my_thread.detach();
    try
    {
        do_something_in_current_thread();
    }
    catch(const std::exception& e)
    {
        my_thread.join();
        std::cerr << e.what() << '\n';
    }
    my_thread.join();
}

int main()
{
    oops();
    return 0;
}